<?php

namespace common\components;

use yii\filters\PageCache as PCache;

/**
 * 重写页面缓存，增加varByParam参数一列
 */
class PageCache extends PCache {

    /**
     * @return array the key used to cache response properties.
     * @since 2.0.3
     */
    protected function calculateCacheKey()
    {
        $key = [__CLASS__];
        if ($this->varyByRoute) {
            // $key[] = Yii::$app->requestedRoute; // 这是源代码，修改为下面后，可以支持view等带参数页面的缓存。
            // $key[] = \Yii::$app->requestedRoute.'/'.implode('/',\Yii::$app->controller->actionParams);
            $key[] = \Yii::$app->request->getUrl();
        }
        if (is_array($this->variations)) {
            foreach ($this->variations as $value) {
                $key[] = $value;
            }
        }
        return $key;
    }

}

?>